package com.cn.bukeManage.pojo.page;
/**
 * @author wyw
 *
 */
public class Page {
	private int currentPage=1; //当前页码
	private int pageSize=10; //一页数据的条数
	private int begin; //开始的序号
	private int end; //结束的序号
	private int rows;  //一共的行数
	private int totalPage; //总页数
	private int sort;//排序
	private String search;//关键字
	
	public Page(){
		
	}
	
	public Page(PageBuilder builder){
		this.currentPage=builder.currentPage;
		this.pageSize=builder.pageSize;
		this.begin=builder.begin;
		this.end=builder.end;
		this.rows=builder.rows;
		this.totalPage=builder.totalPage;
		this.sort=builder.sort;
		this.search=builder.search;
	}
	
		public static class PageBuilder{
			private int currentPage=1; //当前页码
			private int pageSize=10; //一页数据的条数
			private int begin=0; //开始的序号
			private int end=0; //结束的序号
			private int rows=0;  //一共的行数
			private int totalPage=0; //总页数
			private int sort=0;//排序
			private String search="";//关键字
			
			public PageBuilder(){
				
			}
			
			public PageBuilder currentPage(int currentPage){
				this.currentPage=currentPage;
				return this;
			}
			public PageBuilder pageSize(int pageSize){
				this.pageSize=pageSize;
				return this;
			}
			public PageBuilder begin(int begin){
				this.begin=begin;
				return this;
			}
			public PageBuilder end(int end){
				this.end=end;
				return this;
			}
			public PageBuilder rows(int rows){
				this.rows=rows;
				return this;
			}
			public PageBuilder totalPage(int totalPage){
				this.totalPage=totalPage;
				return this;
			}
			public PageBuilder sort(int sort){
				this.sort=sort;
				return this;
			}
			public PageBuilder search(String search){
				this.search=search;
				return this;
			}
			
			public Page builder(){
				return new Page(this);
			}
			
		}
	
	
	
	public String getSearch() {
		return search;
	}
	public void setSearch(String search) {
		this.search = search;
	}
	public int getSort() {
		return sort;
	}
	public void setSort(int sort) {
		this.sort = sort;
	}
	public int getBegin() {
		begin = (currentPage - 1) * pageSize;
		return begin;
	}
	public int getEnd() {
		end = currentPage * pageSize + 1;
		return end;
	}
	public int getTotalPage() {
		if (rows % pageSize == 0) {
			totalPage = rows / pageSize;
		} else {
			totalPage = rows / pageSize + 1;
		}
		return totalPage;
	}
	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
		if (currentPage > getTotalPage()) {
			currentPage = getTotalPage();
		}
	}
	@Override
	public String toString() {
		return "Page [currentPage=" + currentPage + ", pageSize=" + pageSize + ", begin=" + begin + ", end=" + end
				+ ", rows=" + rows + ", totalPage=" + totalPage + "]";
	}
	
	
}



